<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<!--<button type="button" id="htmlPrint">html打印</button>
<button type="button" id="canvasPrint">canvas打印</button>-->
<h3>直接打印不太行，拿不到源码，可读性太差，建议下载下来打印</h3>

<br/>
<button type="button" id="excelDerive">Excel导出</button>
<button type="button" id="pdfDerive">PDF导出</button>
<h3>PDF图像导出、图片导出效果和PDF导出一样</h3>
<!--<button type="button" id="pdfDerive2">PDF图像导出</button>
<button type="button" id="pngDerive">图片导出</button>-->
</body>
<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
<!--<script src="./jquery.print.js"></script>-->
<script>

  //原理直接调用指定接口
  //TODO 这个需要改成自己的
  let host = 'https://api.boot.jeecg.com/jmreport'

  let parameter = {//自己的真实参数
    "excelConfigId": "636736328753827840",
    "base64Arry": [
      {
        "id": "nVUy533exgQ70OPb",
        "base64": ""
      }
    ],
    "queryParam": {
      "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NDA5MzY0MjIsInVzZXJuYW1lIjoiamVlY2cifQ.YxrK8SyCGefrRffCKVqOp_U_pQOWASlvtqxX69u48NI",
      "pageNo": 1,
      "pageSize": 10
    }
  }



  function ajaxDownload(url, method, data, filename) {
      let xhr = new XMLHttpRequest();
      xhr.open(method, url)
      xhr.responseType = 'blob';
      xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8');
      xhr.onload = function () {
          if (this.status === 200) {
              let blob = this.response;
              let a = document.createElement('a');
              a.href = window.URL.createObjectURL(blob);
              a.download = filename;
              a.click()
          }
      }
      xhr.send(JSON.stringify(data))
  }

  $("#excelDerive").on('click',function () {//excel导出
    let api = '/exportAllExcelStream';
    ajaxDownload(host + api,'POST',parameter,'导出文件.xlsx');
  });

  $("#pdfDerive").on('click',function () {//pdf导出
    let api = '/exportPdfStream';
    ajaxDownload(host + api,'POST',parameter,'导出文件.pdf');
  });

/*  $("#htmlPrint").on('click',function () {//html打印
      let api = '/exportPdfStream';
      let xhr = new XMLHttpRequest();
      xhr.open("POST", host + api)
      xhr.responseType = 'blob';
      xhr.setRequestHeader('Content-Type', 'application/json;charset=utf-8');
      xhr.onload = function () {
          if (this.status === 200) {
              let blob = this.response;
              //这里最好由服务器暂存
              // $("#printIframe").attr("src",window.URL.createObjectURL(blob));
              var iframe = document.getElementById("Box");
              if (iframe.attachEvent) {
                  iframe.attachEvent("onload", function() {
                      //iframe加载完成后你需要进行的操作
                  });
              } else {
                  iframe.onload = function() {
                      //iframe加载完成后你需要进行的操作
                  };
              }
              $('#printIframe').attr("src", window.URL.createObjectURL(blob));

              // setTimeout(function(){
              //     $('#printIframe')[0].contentWindow.print();
              //     }, 15000);


          }
      }
      xhr.send(JSON.stringify(parameter))
  });*/





</script>
</html>
